<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="auto">
      <el-form-item label="SN码" prop="snCode">
        <el-input v-model="queryParams.snCode" placeholder="请输入SN码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工单编号" prop="workorderCode">
        <el-input v-model="queryParams.workorderCode" placeholder="请输入工单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品编码" prop="productCode">
        <el-input v-model="queryParams.productCode" placeholder="请输入产品编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品规格" prop="productSpec">
        <el-input v-model="queryParams.productSpec" placeholder="请输入产品规格" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" @click="handleUpdate" v-hasPermi="['produce:sn:batchEdit']">批量修改sn码</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['produce:sn:export']">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-printer" size="mini" @click="batchPrint" v-hasPermi="['produce:sn:batchPrint']">批量打印sn码</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-printer" size="mini" @click="vehiclePrint('', '0')" v-hasPermi="['produce:carBarcode:batchPrint']">批量打印车载条码</el-button>
      </el-col>
    </el-row>
    <!-- 2024-11-22 djj 实现分页多选功能，设置row-key、:reserve-selection="true"即可;增加ref -->
    <el-table ref="workorderSnRef" v-loading="loading" :data="workorderSnList" row-key="snId" @selection-change="handleSelectionChange" height="calc(100vh - 310px)">
      <el-table-column type="selection" width="55" align="center" :reserve-selection="true" />
      <el-table-column label="序号" align="center" width="50px">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="SN码" align="center" prop="snCode" width="100px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleView(scope.row)">{{
            scope.row.snCode
          }}</el-button>
        </template>
      </el-table-column>

      <el-table-column label="工单编号" align="center" prop="workorderCode" width="100" />
      <el-table-column label="工单生产日期" align="center" prop="workorderTime" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.workorderTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="工单批次" align="center" prop="workorderBatch" />-->
      <!--      <el-table-column label="SN状态" align="center" prop="status" />-->
      <el-table-column label="产品编码" align="center" prop="productCode" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="产品规格" align="center" prop="productSpec" />
      <!--      <el-table-column label="产品单位" align="center" prop="productUnit" />-->
      <el-table-column label="车间名称" align="center" prop="workshopName">
        <template slot-scope="scope">
          <span>{{ scope.row.workshopName || "--" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="产线名称" align="center" prop="lineName">
        <template slot-scope="scope">
          <span>{{ scope.row.lineName || "--" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="工艺路线" width="120" align="center" prop="routeName" />
      <el-table-column label="SN状态" align="center" prop="productSnStatus">
        <template slot-scope="scope">
          <span v-if="scope.row.productSnStatus === 0">未生产</span>
          <span v-else-if="scope.row.productSnStatus === 1">生产中</span>
          <span v-else-if="scope.row.productSnStatus === 2">质检中</span>
          <span v-else-if="scope.row.productSnStatus === 3">已返工</span>
          <span v-else-if="scope.row.productSnStatus === 4">待入库</span>
          <span v-else-if="scope.row.productSnStatus === 5">已入库</span>
          <span v-else>--</span>
        </template>
      </el-table-column>

      <el-table-column label="FQC检验单号" align="center" width="120px" prop="fqcCode">
        <!-- <template slot-scope="scope">
          <dict-tag :options="dict.type.fqc_is_check" :value="scope.row.fqcCheckStatus" />
        </template>-->
      </el-table-column>
      <el-table-column label="检验结果" align="center" prop="fqcCheckResult">
        <template slot-scope="scope">
          <span>
            {{
              scope.row.fqcCheckResult == "0"
                ? "不合格"
                : scope.row.fqcCheckResult == "1"
                  ? "合格"
                  : "--"
            }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mes/pro/workorderSn:workorderSn:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mes/pro/workorderSn:workorderSn:remove']"
          >删除</el-button>-->
          <el-button size="mini" type="text" icon="el-icon-printer" @click="print(scope.row)" v-hasPermi="['produce:sn:batchPrint']">打印条码</el-button>
          <el-button v-if="scope.row.workshopName == '车载'" size="mini" type="text" icon="el-icon-printer" @click="vehiclePrint(scope.row, '1')" v-hasPermi="['produce:carBarcode:batchPrint']">打印车载条码</el-button>
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleReport(scope.row)" v-hasPermi="['produce:prod:debugReport']">产品调试报告</el-button>
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleReplace(scope.row)" v-hasPermi="['produce:sn:edit']">更换SN码</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" :page-sizes="[20,30,45, 50,100, 200, 300, 400, 500]" @pagination="getList" />
    <!-- 产品调试报告 -->
    <!-- <Report></Report> -->
    <!-- 添加或修改工单SN码对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="SN码" prop="snCode">
          <el-input v-model="form.snCode" placeholder="请输入SN码" />
        </el-form-item>
        <el-form-item label="工单编号" prop="workorderCode">
          <el-input v-model="form.workorderCode" placeholder="请输入工单编号" />
        </el-form-item>
        <el-form-item label="工单生产日期" prop="workorderTime">
          <el-date-picker clearable v-model="form.workorderTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择工单生产日期"></el-date-picker>
        </el-form-item>
        <el-form-item label="工单批次" prop="workorderBatch">
          <el-input v-model="form.workorderBatch" placeholder="请输入工单批次" />
        </el-form-item>
        <el-form-item label="产品编码" prop="productCode">
          <el-input v-model="form.productCode" placeholder="请输入产品编码" />
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="车间名称" prop="workshopName">
          <el-input v-model="form.workshopName" placeholder="请输入车间名称" />
        </el-form-item>
        <el-form-item label="产线ids" prop="lineIds">
          <el-input v-model="form.lineIds" placeholder="请输入产线ids" />
        </el-form-item>
        <el-form-item label="工艺路线id" prop="routeId">
          <el-input v-model="form.routeId" placeholder="请输入工艺路线id" />
        </el-form-item>
        <el-form-item label="工艺路线名称" prop="routeName">
          <el-input v-model="form.routeName" placeholder="请输入工艺路线名称" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 产品调试报告 -->
    <el-drawer title="产品调试报告" :visible.sync="drawerVisible" size="80%">
      <Report :reportSn="reportSn"></Report>
    </el-drawer>

    <!-- 更换SN码 -->
    <ReplaceSn v-if="replaceVisible" ref="ReplaceSn"></ReplaceSn>

    <!-- 批量更换SN码 -->
    <batchModification v-if="batchVisible" ref="batchModification"></batchModification>

    <!-- 打印SN码 -->
    <print v-if="printVisible" ref="print"></print>

    <!-- 详情 -->
    <el-drawer title="sn详情" size="80%" :visible.sync="openDetail" @opened="snOpen" @close="cancelDetail">
      <div style="padding: 0 20px">
        <!-- <el-tag size="large" style="font-size: 20px;">基本信息</el-tag> -->
        <el-tag size="large" style="font-size: 20px; margin-bottom: 10px">基本信息</el-tag>
        <hr />
        <el-row :gutter="20">
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <span>SN码：</span>
              <span>{{ formDetail.snCode }}</span>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <span>工单编号：</span>
              <span>{{ formDetail.workorderCode }}</span>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <span>工单生产日期：</span>
              <span>{{ formDetail.workorderTime }}</span>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <span>工单批次：</span>
              <span>{{ formDetail.workorderBatch }}</span>
            </div>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <span>产品编码：</span>
              <span>{{ formDetail.productCode }}</span>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <span>产品名称：</span>
              <span>{{ formDetail.productName }}</span>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <span>产品规格：</span>
              <span>{{ formDetail.productSpec }}</span>
            </div>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <span>车间名称：</span>
              <span>{{ formDetail.productName }}</span>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <span>产线名称：</span>
              <span>{{ formDetail.lineName }}</span>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <span>工艺路线名称：</span>
              <span>{{ formDetail.routeName }}</span>
            </div>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <span>FQC检验单号：</span>
              <span>{{ formDetail.fqcCode }}</span>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <span>检验状态：</span>
              <span>
                <dict-tag :options="dict.type.fqc_is_check" :value="formDetail.fqcCheckStatus" />
              </span>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <span>检验结果：</span>
              <span>
                {{
                  formDetail.fqcCheckResult == "0"
                    ? "不合格"
                    : formDetail.fqcCheckResult == "1"
                      ? "合格"
                      : "--"
                }}
              </span>
            </div>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <span>备注：</span>
              <span>{{ formDetail.remark }}</span>
            </div>
          </el-col>
        </el-row>

        <!-- <el-tag size="large" style="font-size: 20px;margin-top:15px">三码合一</el-tag> -->
        <el-tag size="large" style="font-size: 20px; margin-bottom: 10px; margin-top: 15px">三码合一</el-tag>
        <hr />
        <div class="yardsContent">
          <div class="yardsDiv">
            <div>
              <el-button type="success" plain>SN码（序列码）</el-button>
            </div>
            <!-- 2024-11-22 djj 更改svg为成双成对的格式 -->
            <svg id="jsbarcode1"></svg>
            <!-- <svg id="jsbarcode1" /> -->
            <!-- <div>sn码</div> -->
          </div>
          <div class="yardsDiv">
            <div>
              <el-button type="success" plain>桩编码（ZN码）</el-button>
            </div>
            <div class="qrcode" ref="qrCodeUrl"></div>
            <div class="codetext">{{ proYards.assemblyCode }}</div>
          </div>
          <div class="yardsDiv">
            <div>
              <el-button type="success" plain>售后码</el-button>
            </div>
            <div class="qrcode" ref="qrCodeUrl1"></div>
            <div class="codetext">{{ proYards.aftersaleCode }}</div>
          </div>
        </div>

        <!-- <el-tag size="large" style="font-size: 20px;">物料列表</el-tag> -->
        <el-tag size="large" style="font-size: 20px; margin-bottom: 10px; margin-top: 15px">物料列表</el-tag>
        <hr />
        <el-table v-loading="loading" :data="materialList" row-key="materialList">
          <el-table-column label="序号" align="center" width="50px">
            <template slot-scope="scope">
              <span>{{ scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="物料编号" align="center" prop="itemCode" />
          <el-table-column label="物料名称" align="center" prop="itemName" />
          <el-table-column label="物料规格" align="center" prop="specification" />
          <el-table-column label="物料序列号" align="center" prop="snCodeItem" />
          <el-table-column label="物料数量" align="center" prop="realQuantity" />
          <el-table-column label="单位" align="center" prop="unit" />
          <!-- <el-table-column label="单位" align="center" prop="snCodeItem" />
          <el-table-column label="数量" align="center" prop="snCodeItem" />-->
        </el-table>
        <!-- <div slot="footer" class="drawerFooter">
          <el-button type="primary" @click="cancelDetail">返 回</el-button>
          <el-button type="primary" @click="cancelDetail">取 消</el-button>
        </div>-->
      </div>
    </el-drawer>
  </div>
</template>

<script>
import {
  listWorkorderSn,
  getWorkorderSn,
  delWorkorderSn,
  addWorkorderSn,
  updateWorkorderSn,
  detailsWorkorderSn,
  printSn,
} from "@/api/mes/pro/workorderSn";
import Report from "./report.vue";
import ReplaceSn from "./replaceSn.vue";
import batchModification from "./batchModification.vue";
import print from "./print.vue";
import QRCode from "qrcodejs2";
import JsBarcode from "jsbarcode";
export default {
  name: "WorkorderSn",
  components: { Report, ReplaceSn, print, batchModification },
  dicts: ["fqc_is_check"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      //sncode集合
      sncodeList: [],
      //工单ID集合
      workorderIds: [],
      //转成字符串的sncode
      snCodes: "",
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 产品调试报告
      drawerVisible: false,
      //更换SN码
      replaceVisible: false,
      //批量更换sn码
      batchVisible: false,
      //打印SN码
      printVisible: false,
      reportSn: null,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工单SN码表格数据
      workorderSnList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 详情弹窗
      openDetail: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        snCode: null,
        workorderId: null,
        workorderCode: null,
        workorderTime: null,
        workorderBatch: null,
        status: null,
        productId: null,
        productCode: null,
        productName: null,
        productSpec: null,
        productUnit: null,
        workshopId: null,
        workshopName: null,
        lineIds: null,
        routeId: null,
        routeName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        snCode: [
          {
            required: true,
            message: "SN码不能为空",
            trigger: "blur",
          },
        ],
        workorderId: [
          { required: true, message: "工单id不能为空", trigger: "blur" },
        ],
        workorderCode: [
          { required: true, message: "工单编号不能为空", trigger: "blur" },
        ],
        productId: [
          { required: true, message: "产品id不能为空", trigger: "blur" },
        ],
        workshopId: [
          { required: true, message: "车间id不能为空", trigger: "blur" },
        ],
        routeId: [
          { required: true, message: "工艺路线id不能为空", trigger: "blur" },
        ],
      },
      materialList: [],
      formDetail: {},
      proYards: {},
      batchList: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询工单SN码列表 */
    getList() {
      this.loading = true;
      console.log(this.queryParams);
      let Params = {
        pageNum: this.queryParams["pageNum"],
        pageSize: this.queryParams["pageSize"],
        productSpec: this.queryParams["productSpec"],
        productName: this.queryParams["productName"],
        productCode: this.queryParams["productCode"],
        workorderCode: this.queryParams["workorderCode"],
        snCode: this.queryParams["snCode"],
      };
      listWorkorderSn(Params).then((response) => {
        this.workorderSnList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancelDetail() {
      this.openDetail = false;
      this.resetDetail();
    },

    // 表单重置
    reset() {
      this.form = {
        snId: null,
        snCode: null,
        workorderId: null,
        workorderCode: null,
        workorderTime: null,
        workorderBatch: null,
        status: null,
        productId: null,
        productCode: null,
        productName: null,
        productSpec: null,
        productUnit: null,
        workshopId: null,
        workshopName: null,
        lineIds: null,
        routeId: null,
        routeName: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.$refs.workorderSnRef.clearSelection()
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.$refs.workorderSnRef.clearSelection()
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      //id集合
      this.ids = selection.map((item) => item.snId);
      //sncode集合
      this.sncodeList = selection.map((item) => item.snCode);
      //workorderId工单ID去重后集合
      const strings = selection.map((item) => JSON.stringify({ workorderId: item.workorderId, orderType: item.orderType })) // 1、转化成string类型
      const removeDupList = Array.from(new Set(strings))  // 2、转化为真正的数组
      const result = removeDupList.map((item) => JSON.parse(item)) // 3、字符串类型转化为对象类型
      this.workorderIds = result;

      //转成字符串
      this.snCodes = this.sncodeList.join(",");
      this.queryParams.proWorkorderSnIdList = selection.map(
        (item) => item.snId
      );
      this.batchList = selection;
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加工单SN码";
    },

    /** 批量修改按钮操作 */
    handleUpdate() {
      /* djj 增加按钮弹框判断条件 */
      if (this.ids.length == 0) return this.$message.warning('请选择需要修改的SN码')
      if (this.workorderIds.length > 1) return this.$message.warning('请选择同一个工单下的SN码')
      this.batchVisible = true;
      this.$nextTick(() => {
        this.$refs.batchModification.init(this.ids, this.snCodes, this.workorderIds);
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.snId != null) {
            updateWorkorderSn(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWorkorderSn(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const snIds = row.snId || this.ids;
      this.$modal
        .confirm('是否确认删除工单SN码编号为"' + snIds + '"的数据项？')
        .then(function () {
          return delWorkorderSn(snIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "mes/pro/workorderSn/export",
        {
          ...this.queryParams,
        },
        `workorderSn_${new Date().getTime()}.xlsx`
      );
    },
    // 产看产品调试报告
    handleReport(row) {
      //edit begin by zyj 2024/10/18 解决第二次点击不能正确显示工装机调试数据的问题
      //this.reportSn =row.snCode
      this.reportSn = { snCode: row.snCode };
      //edit end by zyj 2024/10/18 解决第二次点击不能正确显示工装机调试数据的问题
      this.drawerVisible = true;
    },
    //更换SN码
    handleReplace(row) {
      this.reportSn = row.snCode;
      this.replaceVisible = true;
      this.$nextTick(() => {
        this.$refs.ReplaceSn.init(row);
      });
    },
    //打印车载SN码
    vehiclePrint(row, type) {
      let obj = [];
      if (type == "0") {
        // 批量打印
        obj = this.batchList;
        for (let i = 0; i < obj.length; i++) {
          const element = obj[i].workshopId;
          if (element !== 208) {
            this.$message.warning("请选择车载产品打印！！！");
            return false;
          }
        }
        this.batchList;
      } else {
        obj.push(row);
      }
      console.log(obj, "=====obj===");
      this.printVisible = true;
      this.$nextTick(() => {
        this.$refs.print.init(obj);
      });
    },
    print(row) {
      console.log(row);
      let param = [];
      param.push(row);
      console.log(param, "=====打印参数==param======");
      printSn(param).then((response) => {
        this.$modal.msgSuccess(response);
        // if (response.code == 200) {
        //   this.$modal.msgSuccess("打印成功");
        // } else {
        //   this.$modal.msgError("打印失败");
        // }
      });
    },
    // 批量打印sn码
    batchPrint() {
      if (this.batchList && this.batchList.length > 0) {
        printSn(this.batchList).then((response) => {
          console.log(response, "============response============");
          var dt = response + "";
          if (dt.indexOf("打印成功") != -1) {
            this.$modal.msgSuccess("打印成功");
          } else {
            this.$modal.msgError("打印失败");
          }
        });
      } else {
        this.$modal.msgError("请选择数据");
      }
    },
    resetDetail() {
      this.formDetail = {};
      this.materialList = [];
      this.proYards = {};
      this.$refs.qrCodeUrl.innerHTML = "";
      this.$refs.qrCodeUrl1.innerHTML = "";
      this.resetForm("formDetail");
    },
    handleView(row) {
      this.reset();
      const snCode = row.snCode || null;
      detailsWorkorderSn(snCode).then((response) => {
        this.formDetail = response.data?.proWorkorderSn || {};
        this.materialList = response.data?.materialList || [];
        this.proYards = response.data?.proYards || {};
        this.openDetail = true;
      });
    },
    snOpen() {
      console.log(
        document.getElementById("jsbarcode1"),
        this.$refs.qrCodeUrl,
        "====document.getElementById)====="
      );
      this.creatQrCode();
      JsBarcode(document.getElementById("jsbarcode1"), this.formDetail.snCode);
    },
    creatQrCode() {
      var qrcode = new QRCode(this.$refs.qrCodeUrl, {
        text: this.proYards.assemblyCode, // 需要转换为二维码的内容
        width: 100,
        height: 100,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: QRCode.CorrectLevel.H,
      });
      var qrcode1 = new QRCode(this.$refs.qrCodeUrl1, {
        text: this.proYards.aftersaleCode, // 需要转换为二维码的内容
        width: 100,
        height: 100,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: QRCode.CorrectLevel.H,
      });
    },
  },
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.app-container ::v-deep .el-drawer__header > :first-child {
  font-weight: 700 !important;
  font-size: 20px;
}

.yardsContent {
  margin-top: 20px;
  // text-align: center;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;

  div {
    font-size: 18px;
  }
}

.yardsDiv {
  margin: 0 10px;
  display: flex;
  flex-direction: column;
  // justify-content: center;
  align-items: center;
  margin-bottom: 15px;

  button {
    margin-bottom: 10px;
    font-size: 18px;
  }

  .codetext {
    margin-top: 10px;
  }
}

.drawerFooter {
  text-align: right;
  padding: 20px;
}

.bg-purple {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  // span:nth-child(1){
  //   display: inline-block;
  //   width: 110px;
  //   white-space: nowrap;
  //   line-height: 30px;
  // }
}
</style>
